package com.vinjogames.gfx;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.View;

import com.vinjogames.som.entities.Game;

public class GameView extends GLSurfaceView implements SurfaceHolder.Callback {

	private GameRenderer mRenderer;	
	private Activity mActivity;

	public GameView(Activity activity, Game game) {
		super(activity);
		getHolder().addCallback(this);
		setFocusable(true);

		mActivity = activity;
		SpriteSheet.getInstance().setContext(mActivity);
		AnimationSheet.getInstance().setContext(mActivity);
		
		setEGLConfigChooser(8, 8, 8, 8, 16, 8);//For stencil buffer
		
		mRenderer = new GameRenderer(mActivity, game);
		setRenderer(mRenderer);
	}

	public boolean passMessageExample(final View v, final MotionEvent e){
		queueEvent(new Runnable() { //Sends messages to renderer thread
			public void run() {
				//Renderer.handleTouchEvent(v, e);
			}});
		return true;
	}	
	
	public boolean loadAllResources(){
		queueEvent(new Runnable() {
			public void run() {
				mRenderer.loadGameResources();
			}});
		return true;
	}	
	public boolean reloadAllResources(){
		queueEvent(new Runnable() {
			public void run() {
				mRenderer.reloadGameResources();
			}});
		return true;
	}
	
	public void onResume(){
		super.onResume();
		reloadAllResources();
	}
}
